﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations;

namespace Project_1.Models
{
    public class Question
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }
        public int CategoryId { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime UpdateTime { get; set; }
        public int Views { get; set; }
        public string Username { get; set; }
        public string Image { get; set; }
    }

    public class QuestionConfiguration : EntityTypeConfiguration<Question>
    {
        public QuestionConfiguration() : base()
        {
            HasKey(p => p.Id);
            Property(p => p.Id).
                HasColumnName("Id").
                HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).
                IsRequired();
            Property(p => p.Title).
                HasColumnName("Title").
                IsRequired();
            Property(p => p.Content).
                HasColumnName("Content");
            Property(p => p.CategoryId).
                HasColumnName("CategoryId").
                IsRequired();
            Property(p => p.CreateTime).
                HasColumnName("CreateTime").
                IsRequired();
            Property(p => p.UpdateTime).
                HasColumnName("UpdateTime").
                IsRequired();
            Property(p => p.Views).
                HasColumnName("Views").
                IsRequired();
            Property(p => p.Username).
                HasColumnName("Username").
                IsRequired();
            Property(p => p.Image).
                HasColumnName("Image");
            ToTable("Questions");
        }
    }

    public class ViewListModel
    {
        [Display(Name = "Id")]
        public string Id { get; set; }

        [Display(Name = "Title")]
        public string Title { get; set; }

        [Display(Name = "Content")]
        public string Content { get; set; }

        [Display(Name = "CategoryID")]
        public int CategoryID { get; set; }

        [Display(Name = "CreateTime")]
        public DateTime CreateTime { get; set; }

        [Display(Name = "UpdateTime")]
        public DateTime UpdateTime { get; set; }

        [Display(Name = "Views")]
        public int Views { get; set; }


        [Display(Name = "Username")]
        public string Username { get; set; }

        [Display(Name = "Image")]
        public string Image { get; set; }

    }
    public class CreateQuestionModel
    {
        [Required(ErrorMessage = "Please enter title!")]
        [StringLength(100, ErrorMessage = "Title is limited at 100 characters")]
        [Display(Name = "Title")]
        public string Title { get; set; }

        [DataType(DataType.MultilineText)]
        [Display(Name = "Content")]
        public string Content { get; set; }

        [Required(ErrorMessage = "Please choose category!")]
        [Display(Name = "Category")]
        public int CategoryId { get; set; }

        [Display(Name = "Image")]
        public string Image { get; set; }

    }

}